<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //数组的pop()方法删除最后一个单元--返回值是一个删除的最后一个元素
        //如果是空数组利用pop()方法返回一个undefined
        const arr = [2, 4, 6, 7, 8]
        //console.log(arr.pop());
        // console.log(arr);
        Array.prototype.myPop = function () {
            if (this.length < 1) return undefined
            const res = this[this.length - 1]
            this.length = this.length - 1
            return res
            //this.length = [this.length - 1]
            //return this[this.length-1]
        }
        console.log(arr.myPop());
        console.log(arr);


    </script>
</body>

</html>